package scriptrunner.execution;

import org.jgroups.Address;

import scriptrunner.execution.cloud.CloudManager;
import communication.ParameterizedMessage;
import communication.ParameterizedMessageImpl;

public class WriteLogFunction extends Function {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8213380003698743836L;

	WriteLogFunction() {
		super(new String("WRITE_LOG"), new ParameterList() );
		this.pl.add( "logInfo" );
	}
	
	@Override
	public ValueObject Execute(Session se) throws ExecuteErrorException {
		ValueObject logInfo = se.getVariableValue("logInfo");
		if (logInfo != null )
			WriteLog(logInfo.toString() );
		return null;
	}
	
	private void WriteLog( String logInfo ) {
		System.out.println(logInfo);
		ParameterizedMessage requestMsg = new ParameterizedMessageImpl("ScriptExecutionService::WriteLog");
		requestMsg.setAttachment(logInfo);
		
		Address master = CloudManager.getCloudManager("GreenCloud").getMaster();
		CloudManager.getCloudManager("GreenCloud").sendMsg(master, requestMsg);
	}

}
